package com.kuang.add;

import java.util.concurrent.CountDownLatch;

/**
 * @program: juc
 * @description: 计数器
 * @author: 陈恩涛
 * @create: 2021-02-23 09:56
 **/
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        // 总数为6,必须要执行任务的时候了，再使用！
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName()+" go out");
                countDownLatch.countDown(); //数量-1
            },String.valueOf(i)).start();
        }

        countDownLatch.await(); //等待计数器归零，然后再向下执行

        System.out.println("close door!");
    }
}
